<template>
  <div class="my-train">
    <div class="mescroll" ref="mescroll">
      <div class="top">
        <div class="cons" :style="'width: '+(12.8-1.5)*(cate_list.length+1)+'rem'">
          <div class="item add" @click="is_mask = true">
            <p class="title">添加</p>
            <p class="tip">定制方案</p>
          </div>
          <div v-for="(item,index) in cate_list" :key="index" class="item" v-bind:class="{active:index==cate}" @click="onCateClick(item.is_dingzhi, item.miyao, index)">
            <p class="title">{{item.miyao_username}}</p>
            <p class="tip" v-if="item.is_dingzhi==1">{{item.list.is_host_name}}{{item.list.is_deputy_name}}{{item.list.is_child_host_name}}</p>
            <p class="tip" v-else>选择属性</p>
          </div>
        </div>
      </div>
      <div class="audio make-audio-details">
        <aplayer
          :music="musics"
          mode = "sigle"
        />
      </div>
      <p class="con-title">
        <span>课程方案</span>
        <em>私人定制专属方案</em>
      </p>
      <div class="list" v-show="lists && lists.length>0">
        <div v-for="(item,index) in lists" :key="index" class="item" @click="go_plan_detail(item)">
          <img :src="baseUrl + item.original_img" class="left-img" alt="">
          <div class="cons">
            <p class="cons-title">{{item.goods_name}}</p>
            <p class="time">{{item.on_time}}</p>
          </div>
          <img src="@/assets/fanandingzhi07.png" class="right-img" alt="">
        </div>
      </div>
      <div class="none" v-show="noDate">
        <img src="@/assets/sousuomendian04.png" alt="">
        <p>暂无相关内容</p>
      </div>
    </div>
    <div class="mask-div" v-if="is_mask">
      <div class="mask-bg" @click="is_mask = false"></div>
      <div class="content">
        <img src="@/assets/huanyingzixun.png" alt="">
        <p class="title">我们会全心全意为您提供满意的<br>咨询服务</p>
        <p class="tip">若需要增加方案定制次数，请购买增量密钥</p>
        <a class="btn" :href="'tel:'+contPhones">联系客服</a>
      </div>
    </div>
  </div>
</template>

<script>
  import Aplayer from 'vue-aplayer'
  import {myplancate, planmake, baseUrl, contPhone} from '@/api/api'
  import MeScroll from 'mescroll.js'
  import 'mescroll.js/mescroll.min.css'
  export default {
    components: {
      Aplayer
    },
    data () {
      return {
        baseUrl,
        child_list:[],
        lists:[],
        cate:0,
        cate_list:[],
        is_mask: false,
        contPhones: "",
        musics: {
          src: "http://xt.js-education.com/static/images/jin.mp3",
          title: "天赋教育",
        },
        noDate: false,
      }
    },
    created () {
      this.plancate()
      this.cont_phone()
    },
    methods: {
      router (path) {
        this.$router.push(path)
      },
      go_plan_detail(obj){
        let cutType = Number(obj.cat_id);
        if(cutType == 19) cutType = 3;
        if(cutType == 20) cutType = 9;
        if(cutType == 21) cutType = 15;
        if(cutType >= 0 && cutType <= 6){
          this.$router.push({ path: '/makeVideoDetails',query: {goods_id: obj.goods_id,types: 'video'}});
        }else if(cutType >= 7 && cutType <= 12){
          this.$router.push({ path: '/makeVideoDetails',query: {goods_id: obj.goods_id,types: 'audio'}});
        }else if(cutType >= 13 && cutType <= 18){
          this.$router.push({ path: '/makeAudioDetails',query: {goods_id: obj.goods_id}});
        }
      },
      plancate(){
        myplancate().then((res) =>{
          this.cate_list=res.data.data.list
          this.child_list=res.data.data.list[0].list
          if(this.cate_list[0].is_dingzhi == "1"){
            this.mescroll = new MeScroll(this.$refs.mescroll, { 
              up: {
                callback: this.upCallback
              }
            })
          }
        }).catch((err) => {
          console.dir(err)
        })
      },
      upCallback (page) {
          console.log(this.child_list, this.child_list)
        if(this.child_list && this.child_list != ""){
          planmake(this.child_list.is_child_host,this.child_list.is_deputy,this.child_list.is_host,this.child_list.ostatus,page.num).then((res) => {
            if (page.num == 1){
              this.lists = []
            }
            if(res.data == null){
              console.log(1)
              this.mescroll.endErr()
              return
            }
            this.$nextTick(() => {
              this.mescroll.endSuccess(res.data.data.result.length);
            })
            this.lists = this.lists.concat(res.data.data.result)
          console.log(this.lists)
            if(this.lists.length == 0){
              this.noDate = true;
            }
          }).catch((err) => {
            console.dir(err)
            this.mescroll.endErr()
          })
        }else{
          this.$nextTick(() => {
            this.mescroll.endSuccess(0);
            if(this.lists.length == 0){
              this.noDate = true;
            }
          })
        }
      },
      onCateClick(is_dingzhi, miyao, index){
        this.lists=[]
        this.cate=index
        this.child_list=this.cate_list[index].list
        if(is_dingzhi==0){
          this.router({path: './editAttr', query:{miyao: miyao}})
        }else{
          this.mescroll.resetUpScroll()
        }
      },
      cont_phone() {
        contPhone().then((res) => {
          this.contPhones = res.data.data.phone;
        }).catch((err) => {
          console.dir(err)
        })
      }
    }
  }
</script>

<style lang="stylus" scoped>
.my-train
  .mescroll
    background-color #fff
    position fixed
    top 0
    bottom 0
    height auto
    width 100vw
    overflow-x hidden
    .top-img
      float left
    .search
      float left
      width 92%
      margin-left 4%
      text-align center
      background-color #fff
      height 4.5rem
      line-height 4.5rem
      margin-top -2.25rem
      margin-bottom 1rem
      img
        display inline-block
        vertical-align middle
        width 1.6rem
      span
        display inline-block
        vertical-align middle
        font-size 1.3rem
        color #172F6D
        margin-left .5rem
  .top
    width 100%
    overflow auto
    position relative
    height 10.5rem
    margin-bottom 1rem
    .cons
      position absolute
      height 10.5rem
      padding-left 1.5rem
      .item.add
        background-image url('../../assets/fanandingzhi01.png')
      .item
        background-image url('../../assets/daerzi.png')
        background-size cover
        width 12.8rem
        height 10.5rem
        float left
        margin-left -1.5rem
        .title
          color #000
          font-size 1.8rem
          font-weight 500
          text-align center
          margin-top 2.5rem
        .tip
          font-size 1.2rem
          color #656565
          text-align center
        .tip.none-attr
          color #25428B
      .item.active
        background-image url('../../assets/fanandingzhi02.png')
        p
          color #fff
  .audio
    background-color #f5f6fa
    height 7rem
    width 92%
    margin-left 4%
  .con-title
    margin-top 2rem
    padding-left 1.6rem
    span
      line-height 2.3rem
      height 2.3rem
      font-size 1.8rem
      color #333
      font-weight bold
      display inline-block
      vertical-align middle
    em
      border-radius 1.2rem 1.2rem 1.2rem 0px
      background-color #f5f6fa
      height 2.3rem
      line-height 2.3rem
      color #647DBC
      font-size 1.2rem
      padding 0 .5rem
      display inline-block
      vertical-align middle
      margin-left .8rem
  .list
    padding 0 1.5rem
    .item
      padding 2rem 0
      overflow hidden
      border-bottom 1px solid #e6e6e6
      &:last-child
        border none
      .left-img
        height 5rem
        width auto
        margin-right 1.8rem
        float left
      .right-img
        float right
        width 2.6rem
        margin-top 1.2rem
      .cons
        float left
        width calc(100vw - 14rem)
        margin-top .6rem
        .cons-title
          color #333333
          width 100%
          font-size 1.5rem
          font-weight 500
          white-space nowrap
          text-overflow ellipsis
          overflow hidden
          line-height 1.6rem
          height 1.6rem
          margin-bottom .7rem
        .cons-time
          font-size 1.2rem
          color #999
          height 1.4rem
          line-height 1.4rem
  .content
    background-color #fff
    width 72%
    margin-left 14%
    padding .5rem
    box-sizing border-box
    top 13.3rem
    text-align center
    .title
      font-size 1.5rem
      color #333
      margin-top 1rem
      font-weight bold
    .tip
      font-size 1.1rem
      color #333
      height 1.1rem
      line-height 1.1rem
      margin-top 1.8rem
    .btn
      color #172F6D
      border 1px solid #172F6D
      height 3.6rem
      line-height 3.6rem
      text-align center
      border-radius 100px
      display block
      width 20rem
      margin-top 2.5rem
      margin-bottom 1.6rem
      position relative
      left 50%
      margin-left -10rem
      font-size 1.3rem
  .none
    img
      position absolute
      top 33.3rem
      width 7.25rem
      left 50%
      margin-left -3.625rem
    p
      color #666
      font-size 1.3rem
      text-align center
      position absolute
      width 100%
      top 45rem
  .aplayer
    margin 0
    padding 1rem
    background-color #F5F6FA
    border none
    box-shadow none
</style>